package com.pc.admin.test.redpacket;

import java.util.*;


public class Lottery extends Thread {

    ArrayList<Integer> list;

    public Lottery(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {

        while (true) {
            synchronized (Lottery.class) {
                if (list.size() == 0) {
                    break;
                } else {
                    Collections.shuffle(list);
                    Integer remove = list.remove(0);
                    System.out.println(Thread.currentThread().getName() + " 又产生了一个 " + remove + " 元大奖");
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}